home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / imgread.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  77 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *       imgread -
  19.  *        Read an image into arrays of chars or shorts.
  20.  *    see fastimg.c for code to read images into arrays of longs.
  21.  *
  22.  *                Paul Haeberli - 1988
  23.  */
  24. #include "stdio.h"
  25. #include "image.h"
  26.  
  27. short *shortimagedata(name)
  28. char *name;
  29. {
  30.     short *base, *sptr;
  31.     IMAGE *image;
  32.     int y;
  33.  
  34.     if( (image=iopen(name,"r")) == NULL ) {
  35.     fprintf(stderr,"shortimagedata: can't open input file %s\n",name);
  36.     exit(1);
  37.     }
  38.     base = (short *)mymalloc(sizeof(short)*image->xsize*image->ysize);
  39.     sptr = base;
  40.     for(y=0; y<image->ysize; y++) {
  41.     getbwrow(image,sptr,y);
  42.     sptr += image->xsize;
  43.     }
  44.     iclose(image);
  45.     return base;
  46. }
  47.  
  48. char *charimagedata(name)
  49. char *name;
  50. {
  51.     char *base, *cptr;
  52.     short *rbuf, *gbuf, *bbuf;
  53.     IMAGE *image;
  54.     int y;
  55.  
  56.     image = iopen(name,"r");
  57.     if(!image) {
  58.     fprintf(stderr,"charimagedata: can't open image file %s\n",name);
  59.     exit(1);
  60.     }
  61.     base = (char *)mymalloc(image->xsize*image->ysize*sizeof(char));
  62.     rbuf = (short *)mymalloc(image->xsize*sizeof(short));
  63.     if(!base || !rbuf) {
  64.     fprintf(stderr,"charimagedata: can't malloc enough memory\n");
  65.     exit(1);
  66.     }
  67.     cptr = base;
  68.     for(y=0; y<image->ysize; y++) {
  69.     getrow(image,rbuf,y,0);
  70.     stoc(rbuf,cptr,image->xsize);
  71.     cptr += image->xsize;
  72.     }
  73.     iclose(image);
  74.     free(rbuf);
  75.     return base;
  76. }
  77.